﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace ConsoleOwin
{
    public class UserController : ApiController
    {
        [DataContract]
        private class Systemuser
        {
            [DataMember]
            public int Id { get; set; }
            [DataMember]
            public String Name { get; set; }
            [DataMember]
            public int Age { get; set; }
        }

        private List<Systemuser> users = new List<Systemuser>
            {
                new Systemuser{Id = 1,Name ="wang",Age=12},
                new Systemuser{Id = 2,Name ="x",Age=121},
                new Systemuser{Id = 3,Name ="wangx",Age=124},
                new Systemuser{Id = 4,Name ="xwang",Age=142},
            };

        public HttpResponseMessage Get()
        {
            return Request.CreateResponse(HttpStatusCode.OK, users);
        }

        public HttpResponseMessage GetById(int id)
        {
            var user = users.Where(x => x.Id == id).FirstOrDefault();
            if (user == null)
            {
                return Request.CreateResponse(HttpStatusCode.OK, new { code = 1, msg = "nodata" });
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.OK, user);
            }
        }
    }
}